package demo.connectsrc;

import org.apache.flink.api.common.functions.RichMapFunction;

import demo.base.connect.OrderDetail;

public class OrderDetailMapFunction extends RichMapFunction<String, OrderDetail> {
    @Override
    public OrderDetail map(String value) throws Exception {
        String[] splits = value.split(",");
        if (splits.length != 3) {
            System.out.println("OrderDetailMapFunction input error:" + value);
            return OrderDetail.empty();
        } else {
            double sum;
            try {
                sum = Double.parseDouble(splits[2]);
            } catch (NumberFormatException E) {
                E.printStackTrace();
                System.out.println("NumberFormatException: " + E.getMessage());
                return OrderDetail.empty();
            }
            return OrderDetail.of(splits[0], splits[1], sum);
        }
    }
}
